package com.example.arithmeticleetcode.leetcode;

import java.util.Arrays;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-06-29 09:25
 **/
public class Demo35 {

    public static void main(String[] args) {
        int[] arr1 = {1, 2, 3, 4, 5, 10, 6, 7, 8, 9};
        int k1 = 5;
        System.out.println(canArrange(arr1, k1)); //true
        int[] arr2 = {1, 2, 3, 4, 5, 6};
        int k2 = 7;
        System.out.println(canArrange(arr2, k2)); //true
        int[] arr3 = {1, 2, 3, 4, 5, 6};
        int k3 = 10;
        System.out.println(canArrange(arr3, k3)); //false
        int[] arr4 = {-10, 10};
        int k4 = 2;
        System.out.println(canArrange(arr4, k4)); //true
        int[] arr5 = {-1, 1, -2, 2, -3, 3, -4, 4};
        int k5 = 3;
        System.out.println(canArrange(arr5, k5)); // true
        Boolean flag = false;
        System.out.println(flag);
        testBoolean(flag);
        System.out.println(flag);
        Integer status = 1;
        System.out.println(status);
        new Demo35().testInteger(status);
        System.out.println(status);
        System.out.println("-----------");
        System.out.println((1 << 0));
    }

    public void testInteger(Integer status) {
        System.out.println(status);
        status = new Integer(2);
    }

    public static void testBoolean(Boolean flag) {
        flag = true;
    }

    public static boolean canArrange(int[] arr, int k) {
        Arrays.sort(arr);
        int len = arr.length;
        for (int i = 0, total = len / 2; i < total; i++) {
            if ((arr[i] + arr[len - 1 - i]) % k != 0) {
                return false;
            }
        }
        return true;
    }
}
